<?php
/**
 * Created by PhpStorm.
 * User: stone
 * Date: 2017/4/13
 * Time: 10:29
 */

namespace app\api\controller;

use app\api\model\Order as OrderModel;

class Order
{

    /**
     * 每次加载$size条数据，加载$size条数据后，$offest自动增长相应的条数，以便程序读取后续条目信息
     * @param int $offset 偏移量
     * @param int $size 分页大小
     * @param string $type 类型
     * @return 返回订单json对象数组
     */

    public function index($offset = 0, $size = 10, $type = 'all')
    {

        $list = new OrderModel();
        if($type=='all'){
        $list = $list->where("UserId", uid())->limit($offset, $size)->order('Id', "DESC")->select();
        }else{
            $list = $list->where("UserId", uid())->limit($offset, $size)->where('Status',$type)->order('Id', "DESC")->select();
        }
        foreach ($list as $i => $v) {
            $list[$i]['shop'] = db('shop')->where('id', $v['ShopId'])->find();
            $list[$i]['order_goods'] = db('order_goods')->where('OrderId', $v['Id'])->select();
        }


        return json($list);
    }
}